package com.me.chat.service.impl;

import com.me.chat.service.UploadService;
import com.me.chat.service.user.UserService;
import com.me.chat.util.FastDFSClientUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;


/**
 * @Author: qiu
 * @Date: 2021/3/15 10:39
 */
@Service
public class UploadServiceImpl implements UploadService {


    @Autowired
    FastDFSClientUtil fastDFSClientUtil;


    @Autowired
    UserService userService;


    @Value("${aokires.fdfsUploadUrl}")
    private String fdfsUploadUrl;




    @Override
    @Transactional
    public void avatarUpload(MultipartFile multipartFile, String userId) throws Exception{
        //使用fastdfs 工具类上传 头像不需要高清，缩略图就可以
        String filePath = fastDFSClientUtil.uploadFile(multipartFile,200,200,0.5);

        userService.updateUserAvatarByUserId(fdfsUploadUrl+filePath,userId);
    }


}
